;(function () {
  // canvas 实现 watermark
  function __canvasWM({
    // 使用 ES6 的函数默认值方式设置参数的默认取值
    // 具体参见 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/Default_parameters
    container = document.body,
    width = document.documentElement.clientWidth / 2 + 'px',
    height = document.documentElement.clientHeight / 3 + 'px',
    textAlign = 'right',
    textBaseline = 'center',
    font = '15px microsoft yahei',
    fillStyle = 'rgba(102, 102, 102, 0.12)',
    content = window.sessionStorage.getItem('ldjsc_shuiyin') ? window.sessionStorage.getItem('ldjsc_shuiyin') : '',
    rotate = '-45',
    zIndex = 1,
    position = 'absolute'
  } = {}) {
    content = content.split('').join(' ')
    // eslint-disable-next-line
    var args = arguments[0]
    var canvas = document.createElement('canvas')
    canvas.setAttribute('width', width)
    canvas.setAttribute('height', height)

    var ctx = canvas.getContext('2d')
    ctx.textAlign = textAlign
    ctx.translate(0, 20)
    ctx.textBaseline = textBaseline
    ctx.font = font
    ctx.rotate((Math.PI / 180) * rotate)
    ctx.left = '20px'
    ctx.fillStyle = fillStyle
    ctx.fillText(content, parseFloat(width) / 2, parseFloat(height) / 2)
    var base64Url = canvas.toDataURL()
    let min = document.documentElement.clientHeight
    const watermarkDiv = document.createElement('div')
    watermarkDiv.setAttribute('id', 'watermarkDiv')
    watermarkDiv.setAttribute(
      'style',
      `position:absolute;
      top:0px;left:0;
      width:100%;
      height:100%;
      min-height: ${min}px;
      z-index:${zIndex};
      pointer-events:none;
      background-repeat:repeat;
      background-image:url('${base64Url}')`
    )
    container.style.position = position
    // container.style.position = 'absolute'
    container.insertBefore(watermarkDiv, container.firstChild)
  }
  window.__canvasWM = __canvasWM
})() // 调用    __canvasWM({      content: 'QQMusicFE'    })
